//导入axios  npm install axios
import axios from 'axios';
// 创建axios实例对象
const instance = axios.create({
    // 设置项目基准地址
    baseURL:'http://localhost:8089',
    // 设置请求超时时间为5秒
    timeout:5000
})


//设置请求拦截器
instance.interceptors.request.use(
    config=>{
        const token=window.sessionStorage.getItem('token')
        config.headers['Content-Type'] = 'application/json;charset=UTF-8'
        if(token){
           config.headers['token']=token  
        }
        return config
    }
)

//设置响应拦截器
instance.interceptors.response.use(
    response=>{
        return response.data
    },error=>{
        return err.response.data
    }
)

export default instance;